<template>
	<view class="unstacking-instore-edit-page-content">
		<view class="form-view">
			<!-- ******************** -->
			<scan-input-form-item
				class="forma-item"
				label="物料编码"
				v-model="form.materialNo"
				:msg="msg.materialNo"
				:has-search="false"
				:required="true"
			/>
			<scan-input-form-item
				class="forma-item"
				label="图号"
				v-model="form.drawingNo"
				:msg="msg.drawingNo"
				:has-scan="false"
				:has-search="false"
				:required="true"
			/>
			<scan-input-form-item
				class="forma-item"
				label="船号"
				v-model="form.shipNo"
				:msg="msg.shipNo"
				:has-scan="false"
				:has-search="false"
				:required="true"
			/>
			<long-width-height-form-item 
				class="forma-item"
				label="尺寸" 
				:long.sync="form.long" 
				:width.sync="form.wide" 
				:height.sync="form.high"
				:msg="msg.materialspec"
				:required="true"
			/>
			<!-- ******************** -->
		</view>
	</view>
</template>

<script>
import ScanInputFormItem from '@/components/ScanInputFormItem.vue'
import LongWidthHeightFormItem from '@/pages/components/LongWidthHeightFormItem.vue'
const defaultForm = {
	materialNo:'',
	shipNo:'',
	drawingNo:'',
	long:null,
	wide:null,
	high:null
}
export default {
	name:'unstackingInstoreEditPageContent',
	components:{ScanInputFormItem,LongWidthHeightFormItem},
	data(){
		return {
			form:{...defaultForm},
			msg:{
				materialNo:'',
				shipNo:'',
				drawingNo:'',
				materialspec:'',
				noWarn:false
			}
		}
	},
	watch:{
		'form.long'(newVal,oldVal) {
			if (newVal!==oldVal) {
				this.watchSpec()
			}
		},
		'form.wide'(newVal,oldVal) {
			if (newVal!==oldVal) {
				this.watchSpec()
			}
		},
		'form.high'(newVal,oldVal) {
			if (newVal!==oldVal) {
				this.watchSpec()
			}
		},
		'form.materialNo'(newVal,oldVal) {
			if (newVal!==oldVal) {
				this.watchMaterialNo()
			}
		},
		'form.shipNo'(newVal,oldVal) {
			if (newVal!==oldVal) {
				this.watchShipNo()
			}
		},
		'form.drawingNo'(newVal,oldVal) {
			if (newVal!==oldVal) {
				this.watchDrawingNo()
			}
		}
	},
	methods:{
		init(obj){
			this.noWarn = true
			if (obj) {
				this.form = {...obj}
			} else {
				this.form.materialNo = ''
			}
			this.$nextTick(()=>{
				this.noWarn = false
			})
		},
		getFormValues(){
			return {...this.form}
		},
		checkConfirm(){
			let res = {flag:true,data:{}}
			res.data = this.getFormValues()
			if (!res.data.materialNo) {
				this.msg.materialNo = '请录入物料编码！'
				res.flag = false
			} else {
				this.msg.materialNo = ''
			}		
			if (res.flag && (!res.data.long || !res.data.wide || !res.data.high)) {
				this.msg.materialspec = '请录入尺寸！'
				res.flag = false
			} else {
				this.msg.materialspec = ''
			}
			if (res.flag && !res.data.drawingNo) {
				this.msg.drawingNo = '请录入图号！'
				res.flag = false
			} else {
				this.msg.drawingNo = ''
			}
			if (res.flag && !res.data.shipNo) {
				this.msg.shipNo = '请录入船号！'
				res.flag = false
			} else {
				this.msg.shipNo = ''
			}
			return res;
		},
		watchSpec(){
			if (this.form.long && this.form.wide && this.form.high) {
				this.msg.materialspec = ''
			}
		},
		watchMaterialNo(){
			if(!this.form.materialNo && !this.noWarn) {
				this.msg.materialNo = '请录入物料编码！'
			} else {
				this.msg.materialNo = ''
			}
		},
		watchDrawingNo(){
			if(!this.form.drawingNo && !this.noWarn) {
				this.msg.drawingNo = '请录入图号！'
			} else {
				this.msg.drawingNo = ''
			}
		},
		watchShipNo(){
			if(!this.form.shipNo && !this.noWarn) {
				this.msg.shipNo = '请录入船号！'
			} else {
				this.msg.shipNo = ''
			}
		}
	}
}
</script>

<style scoped lang="scss">
.unstacking-instore-edit-page-content{
	height: 100%;
	box-sizing: border-box;
	padding-bottom: 12rpx;
	.form-view{
		height: 100%;
		overflow: auto;
	}
	.forma-item{
		margin-bottom: 24rpx;
	}
}
</style>